package GUI_register;

import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class connectionMySQL_reg {

	Connection con;
	
	public connectionMySQL_reg() {
		String userName = "root";
		String password = "silvan13101985";
		String dbName = "Inselbewohner";
		
		try{
			con = DriverManager.getConnection("jdbc:mysql://localhost", userName, password);
			con.setCatalog(dbName);
		}
		catch(Exception e) {
			System.out.println(e.toString());
		}
	}
	
	public void close() {
		try {
			con.close();
		}
		catch(SQLException e) {
			System.out.println(e.toString()); // ???
		}
		
	}
	
	public  boolean insertNewUser(User us) {
		boolean b = false;
		try {
			Statement s = con.createStatement();
			int idUser = us.getidUser();
			String name = us.getName();
			String prename = us.getprename();
			String loginname = us.getLoginname();
			String password = us.getPassword();
 			int mandant = us.getMandant();
			int role = us.getRole();
			String insertUs = "INSERT INTO User Values ("
					+ idUser + ",'"
					+ name + "','"
					+ prename + "','"
					+ loginname + "','"
					+ password + "','"
					+ mandant + "','"
					+ role + "')";
			System.out.println(insertUs);
			s.executeUpdate(insertUs);
			s.close();
			b = true;
		}
		catch(Exception e) {
			System.out.println(e.toString());
		}
		return b;
	}
	
}
